#include "xmodem.h"
#include "mcu_flash.h"
#include "main.h"


bool app_func_is_ota_busy(void)
{
	
	return false;
}


int arch_erase_func(void)
{
	/* Erase the corresponding sector */
	FLASH_Status re;
	re = EraseCpuFlash(MI_BACKUP_START_ADDR,MI_BACKUP_IMAGE_SIZE/1024);
	
	if(re != FLASH_COMPLETE)
		PRINTF("re == %x",re);
	return re;
}


int arch_ota_func(unsigned char *pbuf, unsigned int len, unsigned int sum)
{
	/* trans data to MCU flash here */
	FLASH_Status re;
	
	uint32_t addr = 0;
	
//	PRINTF("\r\n%02x, %02x, %02x, %02x\r\n",pbuf[0],pbuf[1],pbuf[2],pbuf[3]);
	
	addr = MI_BACKUP_START_ADDR + (sum - len);
//	PRINTF("%x ,%p\r\n",addr, pbuf);
	
	re = WriteCpuFlash(addr,pbuf,len);
	
	if(re != FLASH_COMPLETE) return XMODEM_ERR;
	
	return XMODEM_OK;
}


